﻿namespace Papyrus.Web.Controllers
{
    using System.Web.Mvc;
    using Papyrus.Web.Models;
    using Papyrus.Web.Models.Entities;

    public class LoanController : Controller
    {
        private readonly ILoanRepository repository;

        public LoanController()
            : this(new LoanRepository())
        {
        }

        public LoanController(ILoanRepository repository)
        {
            this.repository = repository;
        }

        public ActionResult Create()
        {         
            return this.View("Create", new LoanViewModel());
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [ValidateAntiForgeryToken]
        [ValidateInput(true)]
        public ActionResult Save(LoanViewModel loanViewModel)
        {
            this.repository.SaveLoan(
                new Loan 
                { 
                    id = loanViewModel.Id, 
                    LoanDate = loanViewModel.LoanDate, 
                    ReturnDate = loanViewModel.ReturnDate });

            return this.View();
        }
    }
}
